VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} fQualityCenter 
   Caption         =   "Quality Center Extraction"
   ClientHeight    =   4800
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   4890
   OleObjectBlob   =   "fQualityCenter.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "fQualityCenter"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit
Option Base 1

Private G_qc As cQualityCenter
Private G_LoginCRC As Long
Private G_data As Variant
Private G_ProgressBar As cProgressBar

Public Function GetData() As Variant
    GetData = G_data
    Unload Me
End Function

Private Sub UserForm_Initialize()
    Set G_qc = New cQualityCenter
End Sub

Private Sub UserForm_Terminate()
    On Error Resume Next
    G_qc.DisconnectProject
    G_qc.Logout
    G_qc.ReleaseConnection
    Set G_qc = Nothing
    Application.Cursor = xlDefault
End Sub

Private Sub UserForm_Activate()
    On Error GoTo Err_:
    Application.Cursor = xlWait
    Application.EnableEvents = False
    Me.Repaint
    If G_qc.Last_Server <> Empty Then
        Me.txt_server.Text = G_qc.Last_Server
        If G_qc.InitConnection(G_qc.Last_Server) Then
            If G_qc.Last_User <> Empty Then
                Me.txt_user.Text = G_qc.Last_User
                If G_qc.Login(G_qc.Last_User, G_qc.Last_Password) Then
                    Me.txt_password.Text = G_qc.Last_Password
                    Set_DomainList G_qc.Get_Domains
                    Set_ProjectList G_qc.Get_Projects(G_qc.Last_Domain)
                    Set_DomainValue G_qc.Last_Domain
                    Set_ProjectValue G_qc.Last_Project
                End If
            End If
        End If
    End If
    Application.EnableEvents = True
    Application.Cursor = xlDefault
    Exit Sub
Err_:
    Application.Cursor = xlDefault
    MsgBox "Error while initialising the form :    " & vbCr & Err.Description, vbCritical
End Sub

Private Sub bt_cancel_Click()
    Unload Me: End
End Sub

Private Sub bt_extract_Click()
    On Error GoTo Err_
    Dim lOptionLabel As Label_T, lOptionAttachement As Boolean
    If Me.txt_server.Text = Empty Then MsgBox "Server is empty ! ", vbCritical: Exit Sub
    If Me.cb_project.Value = Empty Then MsgBox "Project is empty ! ", vbCritical: Exit Sub
    If Me.txt_user.Text = Empty Then MsgBox "User is empty ! ", vbCritical: Exit Sub
    If Me.txt_password.Text = Empty Then MsgBox "Password is empty ! ", vbCritical: Exit Sub

    If G_qc.IsLoggedIn = False Then MsgBox "You must login first ! " & vbCr & Err.Description, vbExclamation
    If G_qc.ConnectToProject(Me.cb_domain.Value, Me.cb_project.Value) = True Then
        Set G_ProgressBar = New cProgressBar
        Set G_qc.ProgressBar = G_ProgressBar
        G_ProgressBar.mShow Me
        lOptionLabel = OptionLabel()
        lOptionAttachement = OptionAttachement()
        If Me.opt_bugs Then
            G_data = G_qc.Get_Full_Factory_Bugs(lOptionLabel, Null, Empty, lOptionAttachement)
        ElseIf Me.opt_requirements Then
            G_data = G_qc.Get_Full_Factory_Requirements(lOptionLabel, Null, Empty, lOptionAttachement)
        ElseIf Me.opt_run Then
            'G_data = G_qc.Get_Full_Factory_TestSet(lOptionLabel, Null, Empty, lOptionAttachement)
            'G_data = G_qc.Get_Full_Factory_Run(lOptionLabel, Null, Empty, lOptionAttachement)
            G_data = G_qc.Get_Full_Factory_TestSet_With_Runs(lOptionLabel, Null, Empty, lOptionAttachement)
        ElseIf Me.opt_tests Then
            G_data = G_qc.Get_Full_Factory_Tests(lOptionLabel, Null, Empty, lOptionAttachement)
        ElseIf Me.opt_tests_steps Then
            G_data = G_qc.Get_Full_Factory_Tests_With_Steps(lOptionLabel, Null, Empty, lOptionAttachement)
        End If
        G_ProgressBar.mHide
        G_qc.DisconnectProject
        G_qc.Logout
        G_qc.ReleaseConnection
    Else
        Exit Sub
    End If
    Me.Hide
    Exit Sub
Err_:
    G_qc.DisconnectProject
    G_qc.Logout
    G_qc.ReleaseConnection
    Unload Me
    MsgBox "Error while extracting :   " & vbCr & Err.Description, vbCritical
End Sub

Private Sub txt_server_Change()
    If Not Application.EnableEvents Then Exit Sub
    If G_qc.IsConnected Then
        If G_qc.IsLoggedIn Then G_qc.Logout
        G_qc.ReleaseConnection
    End If
    Set_ProjectList Array()
    Set_DomainList Array()
End Sub

Private Sub txt_user_Change()
    If Not Application.EnableEvents Then Exit Sub
    If G_qc.IsLoggedIn Then G_qc.Logout
    Set_ProjectList Empty
    Set_DomainList Array()
End Sub

Private Sub txt_password_Change()
    If Not Application.EnableEvents Then Exit Sub
    If G_qc.IsLoggedIn Then G_qc.Logout
    Set_ProjectList Array()
    Set_DomainList Array()
End Sub

Private Sub Set_ProjectList(pList As Variant)
    Application.EnableEvents = False
    Me.cb_project.Clear
    If IsArray(pList) Then Me.cb_project.List = pList
    Application.EnableEvents = True
End Sub

Private Sub Set_ProjectValue(pValue As String)
    Application.EnableEvents = False
    Me.cb_project.Value = pValue
    Application.EnableEvents = True
End Sub

Private Sub Set_DomainList(pList As Variant)
    Application.EnableEvents = False
    Me.cb_domain.Clear
    If IsArray(pList) Then Me.cb_domain.List = pList
    Application.EnableEvents = True
End Sub

Private Sub Set_DomainValue(pValue As String)
    Application.EnableEvents = False
    Me.cb_domain.Value = pValue
    Application.EnableEvents = True
End Sub


Private Sub cb_domain_Enter()
    If Not Application.EnableEvents Then Exit Sub
    If Me.txt_server.Text = Empty Then Exit Sub
    Application.Cursor = xlWait
    If Not G_qc.IsConnected Then G_qc.InitConnection (Me.txt_server.Text)
    If G_qc.IsConnected Then
        If Not G_qc.IsLoggedIn Then
            If G_qc.Login(Me.txt_user.Text, Me.txt_password.Text) Then
                Set_DomainList G_qc.Get_Domains
                Set_ProjectList G_qc.Get_Projects(Empty)
            End If
        End If
    End If
    Application.Cursor = xlDefault
End Sub

Private Sub cb_domain_Change()
    If Not Application.EnableEvents Then Exit Sub
    Application.Cursor = xlWait
    Set_ProjectList G_qc.Get_Projects(Me.cb_domain.Value)
    Application.Cursor = xlDefault
End Sub

Private Property Get OptionLabel() As Label_T
    If Me.opt_user_labels Then
        OptionLabel = Label_T.UserLabel
    ElseIf Me.opt_system_label Then
        OptionLabel = Label_T.SystemLabel
    Else
        OptionLabel = Label_T.SystemAndUserLabels
    End If
End Property

Private Property Get OptionAttachement() As Boolean
    OptionAttachement = Me.cb_attachement
End Property



